题目
https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
翻转数组
- 正序输出 + 翻转数组
辅助栈
- 正序输入栈 + 从栈输入Vector
递归
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
if(!head) return {};
vector<int> t = reversePrint(head->next);
t.push_back(head->val);
return t;
}
};
- 时间复杂度:O(N)
- 空间复杂度:O(1)